<?php
defined('_AppBackMiage') or die('Restricted access');
if(isAdministrateur ()){
    include_once (DS . "backoffice/include/header.php");

    if (isset($_GET['id']) && !empty($_GET['id']))
    {
        $model = new ModelMail($_GET['id']);
        if (isset($_POST['submit']))
        {
            $form = true;
            $errMSG = array();

            if (isset($_POST['nom']) && !empty($_POST['nom']))
            {
                $tmp = $model->setNomModelMail($_POST['nom']);
                if ($tmp['boolOk'] === false)
                {
                    $errMSG['nom'] = $tmp['errmsg'];
                    $form = false;
                }
            }

            if (isset($_POST['texte']) && !empty($_POST['texte']))
            {
                $tmp = $model->setTextModelMail($_POST['texte']);
                if ($tmp['boolOk'] === false)
                {
                    $errMSG['texte'] = $tmp['errmsg'];
                    $form = false;
                }
            }

            if ($form === true)
            {
                $model->insert();
                redirectTo(URLBACK."_mails");
            }

        }
    }
    else
    {
        redirectTo(URLBACK."_mails");
    }

    ?>
    <div id="wrapper">
        <div id="content">
            <div id="box">
                <h3>Ajout d'un modele mail</h3>
                <form id="form" method="post">
                    <fieldset id="personal">
                        <legend>Informations</legend>
                        <label for="nom">Nom du modele</label>
                        <input type="text" name="nom" size="50" value="<?php echo $model->getNomModelMail(); ?>"/>
                        <?php if($form === false): ?>
                            <?php echo $errMSG['nom']; ?>
                        <?php endif; ?>
                        <div style="float:left;">
                            <label for="texte">Patron</label>
                            <textarea name="texte" id="text" style="width:500px; height:250px;"><?php echo stripcslashes($model->getTextModelMail()); ?></textarea>
                            <?php if($form === false): ?>
                                <?php echo $errMSG['texte']; ?>
                            <?php endif; ?>
                        </div>
                        <div>
                            <u>Liste de ShortCodes</u>
                            <br />
                            %Nom%<br />
                            %Prenom%<br />
                            %Email%<br />
                            %MotDePasse%<br />
                            %URL%<br />
                        </div>
                    </fieldset>
                    <div align="center">
                        <input id="button1" type="submit" name="submit" value="Ajouter" />
                        <input id="button2" type="reset" />
                    </div>
                </form>
            </div>
        </div>
        <?php
        include_once (DS . "backoffice/include/sidebar.php");
        include_once (DS . "backoffice/include/footer.php");
}
else
{
    redirectTo(URLBACK);
}
?>